<?php

class PlayerController {

    public static function Init() {
        $rpc = RPC::_getInstance();
        // это user_id соцсети, не наш
        $user_id = $rpc->get('network_user_id');
        $social = $rpc->get('social', 0);

        $user = new User($user_id, $social);

        $first_name = mysql_escape_string($rpc->get('first_name', ''));
        $last_name = mysql_escape_string($rpc->get('last_name', ''));
        $sex = (int) ($rpc->get('sex', 0));
        $photo = mysql_escape_string($rpc->get('photo', ''));

        $profile = $user->getProfile();

        $user->setProperty('first_name', $first_name);
        $user->setProperty('last_name', $last_name);
        $user->setProperty('sex', $sex);
        $user->setProperty('photo', $photo);

        $profile = $user->getProfile();
		$user->setProperty('lastLogin', time(), true);
        $user->save();
        $rpc->addResponse('profile', $profile);
		// new secret to client
		$md5 = md5(conf::$api_id.'_'.$user->user_id.'_'.conf::$api_secret);
		$rpc->addResponse('secret', $md5);

		$rpc->addResponse('config', conf::getClientConfig());
    }

}